package com.kongzue.baseokhttpv3.slice;

import com.kongzue.baseokhttp.util.BaseOkHttp;
import com.kongzue.baseokhttp.util.BaseOkHttpConfig;
import com.kongzue.baseokhttpv3.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.render.Paint;
import ohos.agp.text.SimpleTextLayout;
import ohos.agp.utils.Rect;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class MainAbility2Sclice extends AbilitySlice {
    private Button post;
    private Button get, image, slect, httpsask, file;
    static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG");


    private Button postnew;
    private Button getnew;
    private Button downnew,chaoshi,delete,patch,put,https,gzip,basic,cooike,lanjieqi,cach,header,oauth,event;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main_new);
        BaseOkHttpConfig.getInstance().setReserveServiceUrls(new String[]{"https://www.twitter.com", "https://api.apiopen.top"});
        BaseOkHttpConfig.getInstance().setServiceUrl("https://www.fastmock.site");
        getAuth();
        initView();
        initClick();

    }
    private void initView() {
        postnew = (Button) findComponentById(ResourceTable.Id_post);
        getnew = (Button) findComponentById(ResourceTable.Id_get);
        downnew = (Button) findComponentById(ResourceTable.Id_downOrWebSocket);
        chaoshi = (Button) findComponentById(ResourceTable.Id_chaoshi);

        delete = (Button) findComponentById(ResourceTable.Id_delete);
        patch = (Button) findComponentById(ResourceTable.Id_patch);
        put = (Button) findComponentById(ResourceTable.Id_put);
        https = (Button) findComponentById(ResourceTable.Id_https);
        gzip = (Button) findComponentById(ResourceTable.Id_gzip);
        basic = (Button) findComponentById(ResourceTable.Id_basic);
        cooike = (Button) findComponentById(ResourceTable.Id_cooike);
        lanjieqi = (Button) findComponentById(ResourceTable.Id_lanjieqi);
        cach = (Button) findComponentById(ResourceTable.Id_huancun);
        header = (Button) findComponentById(ResourceTable.Id_header);
        oauth = (Button) findComponentById(ResourceTable.Id_oauth);
        event = (Button) findComponentById(ResourceTable.Id_event);

    }
    private void initClick() {
        oauth.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.OauthAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        event.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.EventAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        header.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.HeaderAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        cach.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.CachAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        lanjieqi.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.LanjieqiAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        cooike.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.CookieAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        basic.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.kongzue.baseokhttpv3")
                        .withAbilityName("com.kongzue.baseokhttpv3.newability.SetingAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        gzip.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.GzipAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        https.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.HttpsAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        put.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.kongzue.baseokhttpv3")
                        .withAbilityName("com.kongzue.baseokhttpv3.newability.PutAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        patch.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.PatchAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        delete.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.kongzue.baseokhttpv3")
                        .withAbilityName("com.kongzue.baseokhttpv3.newability.DeleteAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        chaoshi.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.kongzue.baseokhttpv3")
                        .withAbilityName("com.kongzue.baseokhttpv3.newability.TimeAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        downnew.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.kongzue.baseokhttpv3")
                        .withAbilityName("com.kongzue.baseokhttpv3.MainAbility1")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        postnew.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.kongzue.baseokhttpv3")
                        .withAbilityName("com.kongzue.baseokhttpv3.newability.PostAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        getnew.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.okhttp.okhttpdemo")
                        .withAbilityName("com.okhttp.okhttpdemo.newability.GetAbility")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
    }



    private void getAuth() {
        String[] per = {"ohos.permission.READ_USER_STORAGE", "ohos.permission.WRITE_MEDIA",
                "ohos.permission.READ_MEDIA", "ohos.permission.WRITE_USER_STORAGE"};
        requestPermissionsFromUser(per, 0);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
